#ifndef _HAL_I2C_H_
#define _HAL_I2C_H_

#include "bsp.h"

#define I2C1_GPIO_PORT            GPIOB
#define I2C1_GPIO_PeriphClockFunc RCC_AHB1PeriphClockCmd
#define I2C1_GPIO_PeriphClock     RCC_AHB1Periph_GPIOB
#define I2C1_GPIO_SCL             GPIO_Pin_6
#define I2C1_GPIO_SDA             GPIO_Pin_7

#define SDA_IN()                 {GPIOB->MODER&=~(3<<(7*2));GPIOB->MODER|=0<<7*2;}
#define SDA_OUT()                {GPIOB->MODER&=~(3<<(7*2));GPIOB->MODER|=1<<7*2;}

#define IIC1_WR_SCL                PBout(6) //SCL
#define IIC1_WR_SDA                PBout(7) //SDA	 
#define IIC1_RD_SDA                PBin(7)  //RD_SDA 


int8_t hal_SW_iic_start(void);
int8_t hal_SW_iic_stop(void);
int8_t hal_SW_iic_waitack(void);
void hal_SW_iic_ack(void);
void hal_SW_iic_nack(void);
void hal_SW_iic_wr_byte(uint8_t txd);
uint8_t hal_SW_iic_rd_byte(bool ack);
int8_t hal_SW_iic_init(void);
#endif

